package com.company.genealogy.web.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.company.genealogy.web.entity.FamilyNews;
import com.company.genealogy.web.mapper.FamilyNewsMapper;
import com.company.genealogy.web.service.FamilyNewsService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class FamilyNewsServiceImpl extends ServiceImpl<FamilyNewsMapper, FamilyNews> implements FamilyNewsService {

    @Override
    public boolean hasUserLiked(Long newsId, Long userId) {
        return baseMapper.countUserLike(newsId, userId) > 0;
    }
    @Override
    public void likeNews(Long newsId, Long userId) {
        baseMapper.insertUserLike(newsId, userId);
        baseMapper.incrementLikeCount(newsId);
    }
    
    @Override
    public void unlikeNews(Long newsId, Long userId) {
        baseMapper.deleteUserLike(newsId, userId);
        baseMapper.decrementLikeCount(newsId);
    }
    
    @Override
    public List<Map<String, Object>> getNewsLikes(List<Long> newsIds) {
        if (newsIds == null || newsIds.isEmpty()) {
            return new ArrayList<>();
        }
        return baseMapper.getNewsLikes(newsIds);
    }
    
    @Override
    public List<Map<String, Object>> getUserLikes(Long userId, List<Long> newsIds) {
        if (userId == null || newsIds == null || newsIds.isEmpty()) {
            return new ArrayList<>();
        }
        return baseMapper.getUserLikes(userId, newsIds);
    }
} 